package com.cm.projectx.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * 注入RestTemplate
 */
@Component
public class RestTemplateConfig{

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 创建HTTP请求工厂
     * @return 配置完成的ClientHttpRequestFactory实例
     */
    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(5000); // 连接超时时间5秒
        factory.setReadTimeout(10000);   // 读取超时时间10秒
        return factory;
    }



}
